package org.lg.studyspringboot20.service;

import org.lg.studyspringboot20.dao.AdminDao;
import org.lg.studyspringboot20.dto.DTO;
import org.lg.studyspringboot20.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
import java.util.Optional;

@Service("adminService")
public class AdminServiceImpl implements AdminService{
    @Autowired
    private AdminDao adminDao;

    public AdminDao getAdminDao() {
        return adminDao;
    }

    public void setAdminDao(AdminDao adminDao) {
        this.adminDao = adminDao;
    }

    //查询所有，函数方法  返回值类型   方法名   和参数列表
    public DTO getAllAdmin() throws Exception {
        List<Admin> admins = adminDao.getAllAdmin();
        Optional op = Optional.ofNullable(admins);
        return op.isPresent()?new DTO(200,"查询全部管理员成功",admins):new DTO(420,"没有管理员");
    }

    public DTO add(Admin admin){
        return adminDao.add(admin)>0?new DTO(200,"添加管理员成功",admin):new DTO(420,"添加管理员失败");
    }
    public DTO update(Admin admin){
        return adminDao.update(admin)>0?new DTO(200,"修改管理员成功",admin):new DTO(420,"修改管理员失败");
    }
}
